package bkhech.generator.mp.config;

import cn.hutool.core.util.BooleanUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Objects;

/**
 * 读取代码生成相关配置
 *
 * @author ruoyi
 */
@SuppressWarnings("all")
@Component
@ConfigurationProperties(prefix = "gen")
@PropertySource(value = {"${config.generator}"}, encoding = "UTF-8")
public class GenConfig {

    /**
     * 作者
     */
    public static String author;

    /**
     * 待生成表
     */
    public static List<String> tables;

    /**
     * 生成包路径
     */
    public static String packageName;

    /**
     * 自动去除表前缀，默认是false
     */
    public static boolean autoRemovePre;

    /**
     * 表前缀(类名不会包含表前缀)
     */
    public static String tablePrefix;

    /**
     * 模板资源包名, 默认值：{@link bkhech.generator.mp.constant.GenConstants.VM_TEMPLATE_RESOURCE_PACKAGE_NAME}
     */
    public static String vmTemplateResourcePackageName;

    /**
     * 生成基础路径
     * 通常设置为 你实际项目路径，到 src 这一层目录，默认当前项目目录
     */
    public static String genPath;

    /**
     * 其他属性，特殊自定义属性
     */
    public static GenConfigExtra extra;

    @Value("${author}")
    public void setAuthor(String author) {
        GenConfig.author = author;
    }

    @Value("${tables}")
    public void setTables(List<String> tables) {
        GenConfig.tables = tables;
    }

    @Value("${packageName}")
    public void setPackageName(String packageName) {
        GenConfig.packageName = packageName;
    }

    @Value("${autoRemovePre:}")
    public void setAutoRemovePre(Boolean autoRemovePre) {
        GenConfig.autoRemovePre = BooleanUtil.toBoolean(Objects.toString(autoRemovePre));
    }

    @Value("${tablePrefix:}")
    public void setTablePrefix(String tablePrefix) {
        GenConfig.tablePrefix = tablePrefix;
    }

    @Value("${genPath:}")
    public void setGenPath(String genPath) {
        GenConfig.genPath = genPath;
    }

    @Value("${config.vmTemplateResourcePackageName}")
    public void setVmTemplateResourcePackageName(String vmTemplateResourcePackageName) {
        this.vmTemplateResourcePackageName = vmTemplateResourcePackageName;
    }


    @Autowired
    public void setExtra(GenConfigExtra extra) {
        GenConfig.extra = extra;
    }
}
